﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Security.Server;
namespace LightSwitchApplication
{
    public partial class ApplicationDataService
    {
        partial void Categories_Updating(Category entity)
        {
            entity.Modified = DateTime.Now;
        }

        partial void ComputersByPerson_PreprocessQuery(int? Id, ref IQueryable<Entity> query)
        {
            if (Id.HasValue)
            {
                var workspace = this.DataWorkspace; 
                var ris = workspace.ApplicationData.RIs.Where(ri=>ri.PKID.Id==(int)Id).Cast<RI>();
                List<int> fkids = new List<int>();

                foreach (var ri in ris)
                {
                    fkids.Add(ri.FKID.Id);
                }
                query = (from entity in query
                         where fkids.Contains(entity.Id)
                        select entity).AsQueryable();
            }
        }
    }
}
